package com.bt7274.controller;

import com.bt7274.grace.result.GraceJSONResult;
import com.bt7274.grace.result.ResponseStatusEnum;
import com.bt7274.pojo.bo.UserCheckInBO;
import com.bt7274.pojo.vo.CheckInCalendarVO;
import com.bt7274.pojo.vo.UserCheckInVO;
import com.bt7274.pojo.vo.UserMilestoneRecordVO;
import com.bt7274.service.PermanentPromotionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;


/**
 * @BelongsProject: bt7274-back
 * @BelongsPackage: com.bt7274.controller
 * @Author: Galland
 * @CreateTime: 2025-06-14
 * @Description: 常驻活动接口
 * @Version: 1.0
 */
@Tag(name = "常驻促销活动")
@RestController
@RequestMapping("/api/permanent-promotion")
@RequiredArgsConstructor
public class PermanentPromotionController {
    private  final PermanentPromotionService permanentPromotionService;

    // =========用户接口==========

    @Operation(summary = "每日签到")
    @PostMapping("/check-in")
    public GraceJSONResult dailyCheckIn( String userId){
        UserCheckInBO userCheckInBO = new UserCheckInBO();
        userCheckInBO.setUserId(userId);
        UserCheckInVO result = permanentPromotionService.dailyCheckIn(userCheckInBO);

        if (result.getHasCheckedInToday() && result.getTodayReward() != null) {
            return GraceJSONResult.ok(result);
        }else{
            return GraceJSONResult.errorCustom(ResponseStatusEnum.RE_LOGIN);
        }
    }

    @Operation(summary = "获取签到信息")
    @GetMapping("/check-in/info")
    public GraceJSONResult getCheckInInfo(@RequestAttribute("userId") String userId) {
        UserCheckInVO info = permanentPromotionService.getUserCheckInInfo(userId);
        return GraceJSONResult.ok(info);
    }

    @Operation(summary = "获取签到日历")
    @GetMapping("/check-in/calendar")
    public GraceJSONResult getCheckInCalendar(
            @RequestAttribute("userId") String userId,
            @RequestParam(required = false) Integer year,
            @RequestParam(required = false) Integer month) {
        LocalDate now = LocalDate.now();
        if (year == null) year = now.getYear();
        if (month == null) month = now.getMonthValue();

        List<CheckInCalendarVO> calendar = permanentPromotionService.getCheckInCalendar(userId, year, month);
        return GraceJSONResult.ok(calendar);
    }



}
